<template>
  <div>
    <el-breadcrumb>
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <div ref="chart" style="width: 750px; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "Report",
  data() {
    return {
      // 需要合并的图表数据
      options: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  methods: {
    async showChart() {
        let myChart = echarts.init(this.$refs.chart);
        const {data:res} = await this.$axios.get('reports/type/1')
        
        // 合并配置与获取到的数据
        const chart = {...this.options,...res.data};

        // 将合并的结果渲染到界面
        myChart.setOption(chart);
    },
  },
  mounted() {
    // 显示图表
    this.showChart();
  },
};
</script>

<style lang="less" scope>
</style>